package com.lh.mvc.spitter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.lh.mvc.base.BaseDao;

@Service
public class SpitterService {

	private static final Logger logger = Logger.getLogger(SpitterService.class);
	private int result = 0;

    @Autowired
    @Qualifier("spitterIbatisDao")  //SpitterIbatisDao /spitterDao
    private BaseDao spitterIbatisDao;
	   

    public void setSpitterIbatisDao(BaseDao spitterIbatisDao) {
		this.spitterIbatisDao = spitterIbatisDao;
	}


	public List<Map<String, Object>> getSearchAll() {
		List<Map<String, Object>> resultList = null;
		logger.info("===SpitterService.getSearchAll===start");
		resultList = spitterIbatisDao.searchPersons();
		logger.info("===SpitterService.getSearchAll===end===" + resultList);
		return resultList;
	}

	public Map<String, Object> addUser(Person person) {
		Map<String, Object> resultMap = null;
		logger.info("===SpitterService.addUser===start===="+person);
		result = spitterIbatisDao.addUser(person);

		logger.info("===SpitterService.addUser===end===" + result);
		
		if (result > 0) {
			resultMap = new HashMap<String, Object>();
			resultMap.put("id", result);
		}

		return resultMap;
	}

	public Map<String, Object> getUser(String id) {
		Map<String, Object> resultMap = null;
		logger.info("===SpitterService.getUser===id===="+id);
		resultMap = spitterIbatisDao.getUser(id);

		logger.info("===SpitterService.getUser===end======" + resultMap);
		
		return resultMap;
	}


	public int updateUser(Person person) {
		logger.info("===SpitterService.updateUser===start===="+person);
		result = spitterIbatisDao.updateUser(person);

		logger.info("===SpitterService.updateUser===end===" + result);
		
		return result;
	}


	public boolean deleteUsers(String[] ids) {
		boolean resultBoolean = false;
		logger.info("===SpitterService.deleteUsers===start====" + ids);
		
		resultBoolean = spitterIbatisDao.deleteUsers(ids);
		
		logger.info("===SpitterService.deleteUsers===end===" + resultBoolean);
		
		return true;
	}
	
}
